package com.sphd.emanu.activity.orgsetting;

import android.content.Context;

import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.sphd.emanu.pojo.login.Org;
import com.sphd.emanu.utils.GsonUtil;
import com.wzutils.L;

import java.util.Date;

import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class OrgSettingPresenter extends BasePresenterImpl<OrgSettingContract.View> implements OrgSettingContract.Presenter{

    @Override
    public void selectOrg(Integer org) {
        emanuService.selectOrg(org).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                L.e(response.toString());
                mView.setBean(GsonUtil.GsonToBean(response.body(), Org.class));
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }

    @Override
    public void updateOrg(Integer id, String name, String address, String phone, String openingTime, String closingTime,
                          double xwgs84, double ywgs84, String description, MultipartBody.Part photo) {
        emanuService.updateOrg(id, name, address, phone, openingTime, closingTime, xwgs84, ywgs84, description, photo)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        L.e(res(response)+"------up");
                        mView.setRes(res(response));
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {
                        Error(t);
                    }
                });
    }

    @Override
    public void updateOrg(Integer id, String name, String address, String phone, String openingTime, String closingTime, double xwgs84, double ywgs84, String description) {
        emanuService.updateOrg(id, name, address, phone,openingTime, closingTime, xwgs84, ywgs84, description)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        L.e(response.toString());
                        L.e(res(response)+"------up");
                        mView.setRes(res(response));
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {
                        Error(t);
                    }
                });
    }


}
